const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;


// 配置compression-webpack-plugin压缩
let webpack = require('webpack')
// !!! 需要安装npm i compression-webpack-plugin@5.0.1
let CompressionWebpackPlugin = require('compression-webpack-plugin')
let productionGzipExtensions = ['js', 'css']
let Timestamp = new Date().getTime();

module.exports = {
	configureWebpack: {
		// 文件名添加时间戳，保证更新后无缓存
		output: {
			filename: `[name].${Timestamp}.js`,
			chunkFilename: `[name].${Timestamp}.js`
		},
		// 关闭 webpack 的性能提示
		performance: {
			hints: false
		},
		// externals: {
		// 	'vue': 'Vue',
		// 	'vue-router': 'VueRouter',
		// 	'element-ui': 'ELEMENT',
		// 	'axios': 'axios',
		// 	'vant': 'vant'
		// },
		plugins: [
			new BundleAnalyzerPlugin(),
			// 配置compression-webpack-plugin压缩
			new CompressionWebpackPlugin({
				algorithm: 'gzip',
				test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
				threshold: 10240,
				minRatio: 0.8
			}),
			new webpack.ProvidePlugin({
				$: "jquery",
				jQuery: "jquery",
				"windows.jQuery": "jquery"
			}),
		]
	},
	devServer: {
		disableHostCheck: true,
		proxy: {
			[process.env.VUE_APP_BASE_API]: {
				// target: `http://10.2.12.15:8889`,
				target: `http://127.0.0.1:8889`,
				// target: `http://canteen.tsferp.com`,
				changeOrigin: true,
				pathRewrite: {
					['^' + process.env.VUE_APP_BASE_API]: ''
				}
			}
		}
	}
}
